
# coding: utf-8

# # MySQL 数据库连接

# In[56]:

from sqlalchemy import create_engine


# # 数据同步检查

# In[57]:

def checkdb(val1,val2):
    engine = create_engine(val1, max_overflow=3) 
    connection = engine.connect()
    connection = connection.execution_options(
        isolation_level="READ COMMITTED"
    )
    rs=connection.execute('show slave status')
    data=rs.fetchone()[10:12]
    for d1 in data:
        if d1 != 'Yes':
            print (val2+"数据库有问题")
            str2=val2+"数据库有问题"
            sender = 'mars.wang@apep.com.cn'  
            receiver = ['mars.wang@apep.com.cn',  'wenjun@apep.com.cn']
            subject = 'Aoma DB check'  
            smtpserver = 'mail.apep.com.cn'  
            username = 'mars.wang@apep.com.cn'  
            password = '123qweasdZXC'  
            str3='<html><h1>'+str2+'</h1></html>'
            msg = MIMEText(str3,'html','utf-8')  

            msg['Subject'] = subject  
            msg['to']='wenjun@apep.com.cn,mars.wang@apep.com.cn'      #发送到哪里 
            msg['from']='admin@apep.com.cn'    

            smtp = smtplib.SMTP()  
            smtp.connect('mail.apep.com.cn')  
            smtp.login(username, password)  
            smtp.sendmail(sender, receiver, msg.as_string())  
            smtp.quit() 
            
    connection.close


# In[58]:

wq="mysql+pymysql://mars:mars123@192.168.2.102:3306/test"
yqpw="mysql+pymysql://mars:mars123@192.168.2.102:3307/test"
#ed="mysql+pymysql://mars:mars123@192.168.2.102:3308/test"
#禁用 本地有静态数据
eq="mysql+pymysql://mars:mars123@192.168.2.102:3309/test"
sanq="mysql+pymysql://mars:mars123@192.168.2.102:3310/test"
bs="mysql+pymysql://mars:mars123@192.168.2.102:3311/test"
s4q="mysql+pymysql://mars:mars123@192.168.2.102:3312/test"
js="mysql+pymysql://mars:mars123@192.168.2.102:3313/test"
cm="mysql+pymysql://mars:mars123@192.168.2.102:3314/test"
yqjw="mysql+pymysql://mars:mars123@192.168.2.102:3316/test"
djw="mysql+pymysql://mars:mars123@192.168.2.102:3317/test"
#xx="mysql+pymysql://mars:mars123@192.168.2.102:3318/test"
#禁用 本地有静态数据
s4qjw="mysql+pymysql://mars:mars123@192.168.2.102:3319/test"
s6q="mysql+pymysql://mars:mars123@192.168.2.102:3321/test"
leo="mysql+pymysql://mars:mars123@192.168.2.102:3322/test"
db133="mysql+pymysql://mars:mars123@192.168.2.102:3323/test"
fx="mysql+pymysql://mars:mars123@192.168.2.102:3324/test"
checkdb(wq,"五汽票务")
checkdb(yqpw,"一汽票务")
checkdb(eq,"二汽票务")
checkdb(sanq,"三汽票务")
checkdb(bs,"宝山票务")
checkdb(s4q,"四汽票务")
checkdb(js,"金山票务")
checkdb(cm,"崇明票务")
checkdb(yqjw,"一汽机务")
checkdb(djw,"曾辉大机务")
checkdb(s4qjw,"四汽机务")
checkdb(s6q,"六汽票务")
checkdb(leo,"综合平台")
checkdb(db133,"133平台")
checkdb(fx,"奉贤平台")


print ("all done")